package com.ynny.librarysystemmanager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ynny.librarysystemmanager.entity.Book;
import com.ynny.librarysystemmanager.entity.BookDTO;
import com.ynny.librarysystemmanager.mapper.BookMapper;
import com.ynny.librarysystemmanager.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    BookMapper bookMapper;


    //带上分页功能
    @Override
    public List<Book> findAllBooks(Book book) {

        List<Book> allBooks = bookMapper.getAllBooks(book);
        return allBooks;
    }






    @Override
    public Book findBookById(Integer bookId) {
        return null;
    }

    @Override
    public int addBook(Book book) {
        return 0;
    }

    @Override
    public int disableBook(int bookId, int status) {
        //        (图书被借阅了 不允许禁用 (下架) 图书  )

        return 0;
    }

    @Override
    public int editBook(Book book) {
        return 0;
    }

    @Override
    public PageInfo page(BookDTO dto) {

        //开启分页
        PageHelper.startPage(dto.getPageNum() , dto.getPageSize());

        List<Book> books = bookMapper.getAllBooks(dto);

        PageInfo<Book> pageInfo = new PageInfo<>(books);

        return pageInfo;
    }
}
